package com.example.wujinapi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wujinapi.dao.FavouritesDao;
import com.example.wujinapi.dao.FirsttypeDao;
import com.example.wujinapi.entity.Favourites;
import com.example.wujinapi.entity.Firsttype;
import com.example.wujinapi.entity.Products;
import com.example.wujinapi.entity.Users;
import com.example.wujinapi.service.FirsttypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Firsttype)表服务实现类
 *
 * @author makejava
 * @since 2023-07-15 17:33:52
 */
@Service("firsttypeService")
public class FirsttypeServiceImpl extends ServiceImpl<FirsttypeDao, Firsttype> implements FirsttypeService {

    @Autowired
    private FirsttypeDao firsttypeDao;

    @Override
    public void addFirsttype(Firsttype firsttype) {
        Firsttype Data=firsttypeDao.selectOne(new QueryWrapper<Firsttype>().eq("firstclass", firsttype.getFirstclass()));
        if(Data==null){ //为空才插入新用户
            firsttypeDao.insert(firsttype);
        }
    }

    @Override
    public void updateFirsttype(Firsttype firsttype) {
        Firsttype fdata=firsttypeDao.selectOne(new QueryWrapper<Firsttype>().eq("id", firsttype.getId()));
        if(fdata!=null){
            firsttype.setId(fdata.getId());
            firsttypeDao.updateById(firsttype);
        }
    }

    @Override
    public void deleteFirsttype(int dataId) {
        firsttypeDao.delete(new QueryWrapper<Firsttype>().eq("id",dataId));
    }

    @Override
    public Firsttype getFirsttypeById(int fclassid) {
        Firsttype fdata=firsttypeDao.selectOne(new QueryWrapper<Firsttype>().eq("id", fclassid));
        return fdata!=null?fdata:null;
    }

    @Override
    public List<Firsttype> getFirsttypes() {
        List<Firsttype> listDatas=firsttypeDao.selectList(new QueryWrapper<Firsttype>().orderByDesc("firstsortnum"));
        return listDatas!=null?listDatas:null;
    }
}

